<%@ page import="java.sql.*" %><%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/5/25
  Time: 14:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>Title</title>
    </head>
    <body>
        <%
            String username=request.getParameter("username");
            String password=request.getParameter("password");

            //加载驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
            //获取连接实例
            try(Connection connection=
                        DriverManager.getConnection("jdbc:mysql://localhost:3306/library?serverTimezone=UTC&characterEncoding=utf-8",
                                "root","1111")){
                //预编译SQL语句
                String sql="select * from admin where username=?";
                try(PreparedStatement statement=connection.prepareStatement(sql)) {
                    statement.setString(1, username);
                    //执行查询
                    try (ResultSet resultSet = statement.executeQuery()) {
                        //遍历ResultSet
                        while (resultSet.next()) {
                            if (password.equals(resultSet.getString("password"))) {
                                response.sendRedirect("./main.jsp");


                            } else {
                                response.sendRedirect("./index1.jsp");

                            }
                        }

                    }

                }

            }
            catch (SQLException e) {
                e.printStackTrace();
            }

        %>
    </body>
</html>